/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gbbmgmt;

import java.sql.*;
import java.util.*;
import java.text.*;

/**
 *
 * @author dchapman
 */
public class DBA {
    public static Connection conn = null;
    public static String results = "";

    public static boolean openDBCon(){
        String driver = "com.mysql.jdbc.Driver";
        boolean ct = false;
        try {
            Class.forName(driver).newInstance();
            String url = "jdbc:mysql://" + Global.dbURL + ":" + Global.dbPort + "/" + Global.dbName +
                    "?zeroDateTimeBehavior=convertToNull&jdbcCompliantTruncation=false";
            //Global.dbName += "?zeroDateTimeBehavior=convertToNull";
            conn = DriverManager.getConnection(url,Global.userName,Global.passWord);
            ct = true;
        } catch (Exception e) {
            //e.printStackTrace();
        } finally {
            if (conn == null){
                try {
                    conn.close();
                    conn = null;
                } catch (Exception e){
                    
                }
            }
        }
        return ct;
    }

    public static void closeDBCon(){
        try {
            conn.close();
            conn = null;
        } catch (Exception e) {
            //e.printStackTrace();
        }
    }

    //Get Barrel Aging Data from Database
    public static int BAID;
    public static java.sql.Date BADate;
    public static int BABrew;
    public static float BAVol;
    public static String BANotes;

    public static void GetBarrelAgingData(String ageid){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM BarrelAging WHERE BAID = '" + ageid + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                BAID = rs.getInt("BAID");
                BADate = rs.getDate("BADate");
                BABrew = rs.getInt("BABrew");
                BAVol = rs.getFloat("BAVol");
                BANotes = rs.getString("BANotes");
            }
        } catch (Exception e){
            //e.printStackTrace();
        }
    }

    //Get Data from Beer Database.
    public static String BName;
    public static int BCost;
    public static float BAbv;
    public static float BIbu;
    public static int BSrm;
    public static String BNotes;
    public static int RecipeID;
    public static boolean InProduction;
    public static int BId;

    public static void GetBeerData(String BeerID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Beer WHERE BId = '" + BeerID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                BId = rs.getInt("BId");
                BName = rs.getString("BName");
                BCost = rs.getInt("BCost");
                BAbv = rs.getFloat("BAbv");
                BIbu = rs.getFloat("BIbu");
                BSrm = rs.getInt("BSrm");
                BNotes = rs.getString("BNotes");
                RecipeID = rs.getInt("RecipeID");
                InProduction = rs.getBoolean("InProduction");
            }
        } catch (Exception e){
            //e.printStackTrace();
        }
    }

    //Get Beer Inventory Data.
    public static int BIId;
    public static int BIBId;
    public static int BIHalf;
    public static int BIQtr;
    public static int BISix;
    public static int BITT;
    public static int BITW;
    public static int BISF;

    public static void GetBeerInventoryData(String BIID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM BeerInventory WHERE BIId = '" + BIID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                BIId = rs.getInt("BIId");
                BIBId = rs.getInt("BIBId");
                BIHalf = rs.getInt("BIHalf");
                BIQtr = rs.getInt("BIQtr");
                BISix = rs.getInt("BISix");
                BITT = rs.getInt("BITT");
                BITW = rs.getInt("BITW");
                BISF = rs.getInt("BISF");
            }
        } catch (Exception e){
            //e.printStackTrace();
        }
    }

    //Get BrewNote Data from Database
    public static int BNID;
    public static float mlbs01;
    public static float mlbs02;
    public static float mlbs03;
    public static float mlbs04;
    public static float mlbs05;
    public static float mlbs06;
    public static float mlbs07;
    public static float mlbs08;
    public static float mlbs09;
    public static float mlbs10;
    public static float Gypsum;
    public static float CaCl;
    public static float EpsomSalt;
    public static float TableSalt;
    public static float Chalk;
    public static java.sql.Time HydStart;
    public static java.sql.Time HydStop;
    public static float flowrate;
    public static float HydTemp;
    public static float MashTemp;
    public static java.sql.Time MashStop;
    public static String MashNotes;
    public static java.sql.Time VorStart;
    public static java.sql.Time VorStop;
    public static String VorNotes;
    public static float SpargeTemp;
    public static float SpargeBrix;
    public static java.sql.Time SpargeStop;
    public static String SpargeNotes;
    public static float PBVol;
    public static float PBBrix;
    public static java.sql.Time BoilStart;
    public static java.sql.Time BoilStop;
    public static int HNum1;
    public static java.sql.Time H1Time;
    public static float H1lbs;
    public static int HNum2;
    public static java.sql.Time H2Time;
    public static float H2lbs;
    public static int HNum3;
    public static java.sql.Time H3Time;
    public static float H3lbs;
    public static int HNum4;
    public static java.sql.Time H4Time;
    public static float H4lbs;
    public static int HNum5;
    public static java.sql.Time H5Time;
    public static float H5lbs;
    public static int HNum6;
    public static java.sql.Time H6Time;
    public static float H6lbs;
    public static int HNum7;
    public static java.sql.Time H7Time;
    public static float H7lbs;
    public static int HNum8;
    public static java.sql.Time H8Time;
    public static float H8lbs;
    public static int HNum9;
    public static java.sql.Time H9Time;
    public static float H9lbs;
    public static int HNum10;
    public static java.sql.Time H10Time;
    public static float H10lbs;
    public static java.sql.Time WhirlStop;
    public static java.sql.Time RestStop;
    public static java.sql.Time KOStop;
    public static float KOTemp;
    public static float VolFinal;
    public static float BOG;
    public static float BOxy;
    public static float MashpH;
    public static float SpargepH;
    public static float BoilpH;

    public static void GetBrewNotesData(String BrNID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM BrewNotes WHERE BNID = '" + BrNID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                BNID = rs.getInt("BNID");
                mlbs01 = rs.getFloat("mlbs01") ;
                mlbs02 = rs.getFloat("mlbs02") ;
                mlbs03 = rs.getFloat("mlbs03") ;
                mlbs04 = rs.getFloat("mlbs04") ;
                mlbs05 = rs.getFloat("mlbs05") ;
                mlbs06 = rs.getFloat("mlbs06") ;
                mlbs07 = rs.getFloat("mlbs07") ;
                mlbs08 = rs.getFloat("mlbs08") ;
                mlbs09 = rs.getFloat("mlbs09") ;
                mlbs10 = rs.getFloat("mlbs10") ;
                Gypsum = rs.getFloat("Gypsum") ;
                CaCl = rs.getFloat("CaCl") ;
                EpsomSalt = rs.getFloat("EpsomSalt") ;
                TableSalt = rs.getFloat("TableSalt") ;
                Chalk = rs.getFloat("Chalk") ;
                HydStart = rs.getTime("HydStart") ;
                HydStop = rs.getTime("HydStop") ;
                flowrate = rs.getFloat("flowrate") ;
                HydTemp = rs.getFloat("HydTemp") ;
                MashTemp = rs.getFloat("MashTemp") ;
                MashStop = rs.getTime("MashStop") ;
                MashNotes = rs.getString("MashNotes") ;
                VorStart = rs.getTime("VorStart") ;
                VorStop = rs.getTime("VorStop") ;
                VorNotes = rs.getString("VorNotes") ;
                SpargeTemp = rs.getFloat("SpargeTemp") ;
                SpargeBrix = rs.getFloat("SpargeBrix") ;
                SpargeStop = rs.getTime("SpargeStop") ;
                SpargeNotes = rs.getString("SpargeNotes") ;
                PBVol = rs.getFloat("PBVol") ;
                PBBrix = rs.getFloat("PBBrix") ;
                BoilStart = rs.getTime("BoilStart") ;
                BoilStop = rs.getTime("BoilStop") ;
                HNum1 = rs.getInt("HNum1") ;
                H1Time = rs.getTime("H1Time") ;
                H1lbs = rs.getFloat("H1lbs") ;
                HNum2 = rs.getInt("HNum2") ;
                H2Time = rs.getTime("H2Time") ;
                H2lbs = rs.getFloat("H2lbs") ;
                HNum3 = rs.getInt("HNum3") ;
                H3Time = rs.getTime("H3Time") ;
                H3lbs = rs.getFloat("H3lbs") ;
                HNum4 = rs.getInt("HNum4") ;
                H4Time = rs.getTime("H4Time") ;
                H4lbs = rs.getFloat("H4lbs") ;
                HNum5 = rs.getInt("HNum5") ;
                H5Time = rs.getTime("H5Time") ;
                H5lbs = rs.getFloat("H5lbs") ;
                HNum6 = rs.getInt("HNum6") ;
                H6Time = rs.getTime("H6Time") ;
                H6lbs = rs.getFloat("H6lbs") ;
                HNum7 = rs.getInt("HNum7") ;
                H7Time = rs.getTime("H7Time") ;
                H7lbs = rs.getFloat("H7lbs") ;
                HNum8 = rs.getInt("HNum8") ;
                H8Time = rs.getTime("H8Time") ;
                H8lbs = rs.getFloat("H8lbs") ;
                HNum9 = rs.getInt("HNum9") ;
                H9Time = rs.getTime("H9Time") ;
                H9lbs = rs.getFloat("H9lbs") ;
                HNum10 = rs.getInt("HNum10") ;
                H10Time = rs.getTime("H10Time") ;
                H10lbs = rs.getFloat("H10lbs") ;
                WhirlStop = rs.getTime("WhirlStop") ;
                RestStop = rs.getTime("RestStop") ;
                KOStop = rs.getTime("KOStop") ;
                KOTemp = rs.getFloat("KOTemp") ;
                VolFinal = rs.getFloat("VolFinal") ;
                BOG = rs.getFloat("BOG") ;
                BOxy = rs.getFloat("BOxy") ;
                MashpH = rs.getFloat("MashpH") ;
                SpargepH = rs.getFloat("SpargepH") ;
                BoilpH = rs.getFloat("BoilpH") ;
            }
        } catch (Exception e){
            //e.printStackTrace();
        }
    }


    //Get Brew Data from Database
    public static int BID;
    public static int BrewNoteID;
    public static int BrewNoteID2;
    public static int BrewNoteID3;
    public static int BrewNoteID4;
    public static int BrewNoteID5;
    public static int BrewNoteID6;
    public static int RID;
    public static int BBeerID;
    public static int BState;
    public static java.sql.Date BDate;
    public static int BEID;
    public static int YeastID;
    public static float YeastVol;
    public static java.sql.Time PitchTime;
    public static float PFTemp01;
    public static float PFGrav01;
    public static java.sql.Date PFDate01;
    public static java.sql.Time PFTime01;
    public static String PFNote01;
    public static float PFTemp02;
    public static float PFGrav02;
    public static java.sql.Date PFDate02;
    public static java.sql.Time PFTime02;
    public static String PFNote02;
    public static float PFTemp03;
    public static float PFGrav03;
    public static java.sql.Date PFDate03;
    public static java.sql.Time PFTime03;
    public static String PFNote03;
    public static float PFTemp04;
    public static float PFGrav04;
    public static java.sql.Date PFDate04;
    public static java.sql.Time PFTime04;
    public static String PFNote04;
    public static float PFTemp05;
    public static float PFGrav05;
    public static java.sql.Date PFDate05;
    public static java.sql.Time PFTime05;
    public static String PFNote05;
    public static float PFTemp06;
    public static float PFGrav06;
    public static java.sql.Date PFDate06;
    public static java.sql.Time PFTime06;
    public static String PFNote06;
    public static float PFTemp07;
    public static float PFGrav07;
    public static java.sql.Date PFDate07;
    public static java.sql.Time PFTime07;
    public static String PFNote07;
    public static float DRTemp01;
    public static float DRGrav01;
    public static java.sql.Date DRDate01;
    public static java.sql.Time DRTime01;
    public static String DRNote01;
    public static float YCTemp01;
    public static float YCGrav01;
    public static java.sql.Date YCDate01;
    public static java.sql.Time YCTime01;
    public static String YCNote01;
    public static float SFTemp01;
    public static float SFGrav01;
    public static java.sql.Date SFDate01;
    public static java.sql.Time SFTime01;
    public static String SFNote01;
    public static float BTG;
    public static java.sql.Date CTDate;
    public static java.sql.Time CTTime;
    public static float BPSI;
    public static float CTTemp;
    public static java.sql.Date PDate;
    public static java.sql.Time PTime;
    public static float VolLeft;
    public static float SFVol01;
    public static float CTVol;
    public static int BNDHHop1;
    public static float BNDHLbs1;
    public static java.sql.Date BNDHSt1;
    public static java.sql.Date BNDHFn1;
    public static int BNDHHop2;
    public static float BNDHLbs2;
    public static java.sql.Date BNDHSt2;
    public static java.sql.Date BNDHFn2;
    public static int BNDHHop3;
    public static float BNDHLbs3;
    public static java.sql.Date BNDHSt3;
    public static java.sql.Date BNDHFn3;
    public static int BNDHHop4;
    public static float BNDHLbs4;
    public static java.sql.Date BNDHSt4;
    public static java.sql.Date BNDHFn4;
    public static int PFVID;
    public static int SFVID;
    public static int CVID;
    public static float KegVols;
    public static float BtlVols;
    public static int PitchType;
    public static int HarvVes;
    public static int HarvBatch;
    public static int YeastGen;
    public static int YeastGenId;
    public static String TString;

    public static void GetBrewsData(String BrID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Brews WHERE BID = '" + BrID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                BID = rs.getInt("BID");
                BrewNoteID = rs.getInt("BrewNoteID");
                BrewNoteID2 = rs.getInt("BrewNoteID2");
                BrewNoteID3 = rs.getInt("BrewNoteID3");
                BrewNoteID4 = rs.getInt("BrewNoteID4");
                BrewNoteID5 = rs.getInt("BrewNoteID5");
                BrewNoteID6 = rs.getInt("BrewNoteID6");
                RID = rs.getInt("RID");
                BBeerID = rs.getInt("BBeerID");
                BState = rs.getInt("BState");
                BDate = rs.getDate("BDate");
                BEID = rs.getInt("BEID") ;
                YeastID = rs.getInt("YeastID") ;
                YeastVol = rs.getFloat("YeastVol") ;
                PitchTime = rs.getTime("PitchTime") ;
                PFVID = rs.getInt("PFVID") ;
                SFVID = rs.getInt("SFVID") ;
                CVID = rs.getInt("CVID") ;
                PFTemp01 = rs.getFloat("PFTemp01") ;
                PFGrav01 = rs.getFloat("PFGrav01") ;
                PFDate01 = rs.getDate("PFDate01") ;
                PFTime01 = rs.getTime("PFTime01") ;
                PFNote01 = rs.getString("PFNote01") ;
                PFTemp02 = rs.getFloat("PFTemp02") ;
                PFGrav02 = rs.getFloat("PFGrav02") ;
                PFDate02 = rs.getDate("PFDate02") ;
                PFTime02 = rs.getTime("PFTime02") ;
                PFNote02 = rs.getString("PFNote02") ;
                PFTemp03 = rs .getFloat("PFTemp03");
                PFGrav03 = rs.getFloat("PFGrav03") ;
                PFDate03 = rs.getDate("PFDate03") ;
                PFTime03 = rs.getTime("PFTime03") ;
                PFNote03 = rs.getString("PFNote03") ;
                PFTemp04 = rs.getFloat("PFTemp04") ;
                PFGrav04 = rs.getFloat("PFGrav04") ;
                PFDate04 = rs.getDate("PFDate04") ;
                PFTime04 = rs.getTime("PFTime04") ;
                PFNote04 = rs.getString("PFNote04") ;
                PFTemp05 = rs.getFloat("PFTemp05") ;
                PFGrav05 = rs.getFloat("PFGrav05") ;
                PFDate05 = rs.getDate("PFDate05") ;
                PFTime05 = rs.getTime("PFTime05") ;
                PFNote05 = rs.getString("PFNote05") ;
                PFTemp06 = rs.getFloat("PFTemp06") ;
                PFGrav06 = rs.getFloat("PFGrav06") ;
                PFDate06 = rs.getDate("PFDate06") ;
                PFTime06 = rs.getTime("PFTime06") ;
                PFNote06 = rs.getString("PFNote06") ;
                PFTemp07 = rs.getFloat("PFTemp07") ;
                PFGrav07 = rs.getFloat("PFGrav07") ;
                PFDate07 = rs.getDate("PFDate07") ;
                PFTime07 = rs.getTime("PFTime07") ;
                PFNote07 = rs.getString("PFNote07") ;
                DRTemp01 = rs.getFloat("DRTemp01") ;
                DRGrav01 = rs.getFloat("DRGrav01") ;
                DRDate01 = rs.getDate("DRDate01") ;
                DRTime01 = rs.getTime("DRTime01") ;
                DRNote01 = rs.getString("DRNote01") ;
                YCTemp01 = rs.getFloat("YCTemp01") ;
                YCGrav01 = rs.getFloat("YCGrav01") ;
                YCDate01 = rs.getDate("YCDate01") ;
                YCTime01 = rs.getTime("YCTime01") ;
                YCNote01 = rs.getString("YCNote01") ;
                SFTemp01 = rs.getFloat("SFTemp01") ;
                SFGrav01 = rs.getFloat("SFGrav01") ;
                SFDate01 = rs.getDate("SFDate01") ;
                SFTime01 = rs.getTime("SFTime01") ;
                SFNote01 = rs.getString("SFNote01") ;
                BTG = rs.getFloat("BTG") ;
                CTDate = rs.getDate("CTDate") ;
                CTTime = rs.getTime("CTTime") ;
                BPSI = rs.getFloat("BPSI") ;
                CTTemp = rs.getFloat("CTTemp") ;
                PDate = rs.getDate("PDate") ;
                PTime = rs.getTime("PTime") ;
                VolLeft = rs.getFloat("VolLeft") ;
                SFVol01 = rs.getFloat("SFVol01") ;
                CTVol = rs.getFloat("CTVol") ;
                KegVols = rs.getFloat("KegVols");
                BtlVols = rs.getFloat("BtlVols");
                PitchType = rs.getInt("PitchType");
                HarvVes = rs.getInt("HarvVes");
                HarvBatch = rs.getInt("HarvBatch");
                YeastGen = rs.getInt("YeastGen");
                YeastGenId = rs.getInt("YeastGenId");
                BNDHHop1 = rs.getInt("BNDHHop1") ;
                BNDHLbs1 = rs.getFloat("BNDHLbs1") ;
                BNDHSt1 = rs.getDate("BNDHSt1") ;
                BNDHFn1 = rs.getDate("BNDHFn1") ;
                BNDHHop2 = rs.getInt("BNDHHop2") ;
                BNDHLbs2 = rs.getFloat("BNDHLbs2") ;
                BNDHSt2 = rs.getDate("BNDHSt2") ;
                BNDHFn2 = rs.getDate("BNDHFn2") ;
                BNDHHop3 = rs.getInt("BNDHHop3") ;
                BNDHLbs3 = rs.getFloat("BNDHLbs3") ;
                BNDHSt3 = rs.getDate("BNDHSt3") ;
                BNDHFn3 = rs.getDate("BNDHFn3") ;
                BNDHHop4 = rs.getInt("BNDHHop4") ;
                BNDHLbs4 = rs.getFloat("BNDHLbs4") ;
                BNDHSt4 = rs.getDate("BNDHSt4") ;
                BNDHFn4 = rs.getDate("BNDHFn4") ;

            }
        } catch (Exception e){
            //e.printStackTrace();
        }
    }

    //Get Cost Data from Database.
    public static int CostID;
    public static String CostDesc;
    public static float HCost;
    public static float QCost;
    public static float SCost;
    public static float TTCost;
    public static float TWCost;
    public static float SFCost;

    public static void GetCostData(String COSTID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Cost WHERE CostID = '" + COSTID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                CostID = rs.getInt("CostID");
                CostDesc = rs.getString("CostDesc");
                HCost = rs.getFloat("HCost");
                QCost = rs.getFloat("QCost");
                SCost = rs.getFloat("SCost");
                TTCost = rs.getFloat("TTCost");
                TWCost = rs.getFloat("TWCost");
                SFCost = rs.getFloat("SFCost");
            }
        } catch (Exception e){
            //e.printStackTrace();
        }
    }

    //Get Customer Information.
    public static String CName;
    public static String CAddr;
    public static String CCity;
    public static String CState;
    public static int CZip;
    public static String CContact;
    public static String CPhone;
    public static String CNotes;
    public static String CEmail;
    public static int CTerms;
    public static int CId;

    public static void GetCustomerData(String CID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Customer WHERE CId = '" + CID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                CId = rs.getInt("CId");
                CName = rs.getString("CName");
                CAddr = rs.getString("CAddr");
                CCity = rs.getString("CCity");
                CState = rs.getString("CState");
                CZip = rs.getInt("CZip");
                CContact = rs.getString("CContact");
                CPhone = rs.getString("CPhone");
                CNotes = rs.getString("CNotes");
                CEmail = rs.getString("CEmail");
                CTerms = rs.getInt("CTerms");
            }
        } catch (Exception e){
            //e.printStackTrace();
        }
    }

    //Get Discount Data from Database
    public static int DiscID;
    public static String DiscName;
    public static float DiscNum;

    public static void GetDiscountCodeData(String DISCID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM DiscountCode WHERE DiscID = '" + DISCID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                DiscID = rs.getInt("DiscID");
                DiscName = rs.getString("DiscName");
                DiscNum = rs.getFloat("DiscNum");
            }
        } catch (Exception e){
            //e.printStackTrace();
        }
    }

    //Get Employee Data from Database.
    public static int EmpID;
    public static String EmpLastName;
    public static String EmpFirstName;
    public static String userName;
    public static String userPass;
    public static int userLevel;
    public static boolean EmpPOApproval;
    public static boolean EmpSysAdmin;

    public static void GetEmployeeData(String EID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Employee WHERE EmpID = '" + EID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                EmpID = rs.getInt("EmpID");
                EmpLastName = rs.getString("EmpLastName");
                EmpFirstName = rs.getString("EmpFirstName");
                userName = rs.getString("userName");
                userPass = rs.getString("userPass");
                userLevel = rs.getInt("userLevel");
                EmpPOApproval = rs.getBoolean("EmpPOApproval");
                EmpSysAdmin = rs.getBoolean("EmpSysAdmin");
            }
        } catch (Exception e){
            //e.printStackTrace();
        }
    }

    //Get Fermentation Vessel Data
    public static int FVID;
    public static String FVDesg;
    public static String FVName;
    public static String FVMfg;
    public static float FVRate;
    public static float FVCap;
    public static boolean FVPRM;

    public static void GetFVData(String FID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM FV WHERE FVID = '" + FID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                FVID = rs.getInt("FVID");
                FVDesg = rs.getString("FVDesg");
                FVName = rs.getString("FVName");
                FVMfg = rs.getString("FVMfg");
                FVRate = rs.getFloat("FVRate");
                FVCap = rs.getFloat("FVCap");
                FVPRM = rs.getBoolean("FVPRM");
            }
        } catch (Exception e){
            //e.printStackTrace();
        }
    }

    //Get Hop Data from Database
    public static int HID;
    public static String HopName;
    public static float HopAA;
    public static boolean HopWhole;
    public static float HopBagLbs;
    public static float HopOnHand;
    public static float HopSpoken;
    public static float HopOnOrder;

    public static void GetHopsData(String HopID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Hops WHERE HID = '" + HopID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                HID = rs.getInt("HID");
                HopName = rs.getString("HopName");
                HopAA = rs.getFloat("HopAA");
                HopWhole = rs.getBoolean("HopWhole");
                HopBagLbs = rs.getFloat("HopBagLbs");
                HopOnHand = rs.getFloat("HopOnHand");
                HopSpoken = rs.getFloat("HopSpoken");
                HopOnOrder = rs.getFloat("HopOnOrder");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Get Malt Data from Database
    public static int MaltID;
    public static String MaltName;
    public static float MaltColor;
    public static int MaltSG;
    public static int MaltEff;
    public static int MaltBagLbs;
    public static float MaltOnHand;
    public static float MaltSpoken;
    public static float MaltOnOrder;

    public static void GetMaltData(String MID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Malt WHERE MaltID = '" + MID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                MaltID = rs.getInt("MaltID");
                MaltName = rs.getString("MaltName");
                MaltColor = rs.getFloat("MaltColor");
                MaltSG = rs.getInt("MaltSG");
                MaltEff = rs.getInt("MaltEff");
                MaltBagLbs = rs.getInt("MaltBagLbs");
                MaltOnHand = rs.getFloat("MaltOnHand");
                MaltSpoken = rs.getFloat("MaltSpoken");
                MaltOnOrder = rs.getFloat("MaltOnOrder");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Get Movement Data from Database.
    public static int MovementID;
    public static java.sql.Date MovementDate;
    public static int MovementBrewID;
    public static int MovementOldState;
    public static int MovementStateID;
    public static float MovementVolume;
    public static float MovementLoss;
    public static float MovementGain;
    public static int MovementEmpID;
    public static String MovementNotes;
    public static int MovementOVID;
    public static int MovementNVID;

    public static void GetMovementData(String mvmtid){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Movement WHERE MovementID = '" + mvmtid + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                MovementID = rs.getInt("MovementID");
                MovementDate = rs.getDate("MovementDate");
                MovementBrewID = rs.getInt("MovementBrewID");
                MovementOldState = rs.getInt("MovementOldState");
                MovementStateID = rs.getInt("MovementStateID");
                MovementVolume = rs.getFloat("MovementVolume");
                MovementLoss = rs.getFloat("MovementLoss");
                MovementGain = rs.getFloat("MovementGain");
                MovementEmpID = rs.getInt("MovementEmpID");
                MovementNotes = rs.getString("MovementNotes");
                MovementOVID = rs.getInt("MovementOVID");
                MovementNVID = rs.getInt("MovementNVID");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }


    //Get POLines Data from Database
    public static int POLID;
    public static int POLPN;
    public static int POLQty;
    public static boolean POLRcvd;
    public static float POLCost;

    public static void GetPOLinesData(String poid){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM POLines WHERE POLID = '" + poid + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                POLID = rs.getInt("POLID");
                POLPN = rs.getInt("POLPN");
                POLQty = rs.getInt("POLQty");
                POLRcvd = rs.getBoolean("POLRcvd");
                POLCost = rs.getFloat("POLCost");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Get Purchase Order Data from Database
    public static int POID;
    public static String POCSV;
    public static int POState;
    public static java.sql.Date PODate;

    public static void GetPurchaseOrderData(String poid){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM PurchaseOrder WHERE POID = '" + poid + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                POID = rs.getInt("POID");
                POCSV = rs.getString("POCSV");
                POState = rs.getInt("POState");
                PODate = rs.getDate("PODate");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Get Recipe data from Database
    public static int RecpID;
    public static String RName;
    public static int RRev;
    public static float RGT;
    public static float RVol;
    public static int MName01;
    public static float Mpct01;
    public static int MName02;
    public static float Mpct02;
    public static int MName03;
    public static float Mpct03;
    public static int MName04;
    public static float Mpct04;
    public static int MName05;
    public static float Mpct05;
    public static int MName06;
    public static float Mpct06;
    public static int MName07;
    public static float Mpct07;
    public static int MName08;
    public static float Mpct08;
    public static int MName09;
    public static float Mpct09;
    public static int MName10;
    public static float Mpct10;
    public static float gGypsum;
    public static float gCaCl;
    public static float gEpsomSalt;
    public static float gChalk;
    public static float gTableSalt;
    public static int HName01;
    public static float AApct01;
    public static float hlbs01;
    public static boolean fwh1;
    public static int HName02;
    public static float AApct02;
    public static float hlbs02;
    public static boolean fwh2;
    public static int HName03;
    public static float AApct03;
    public static float hlbs03;
    public static int HName04;
    public static float AApct04;
    public static float hlbs04;
    public static int HName05;
    public static float AApct05;
    public static float hlbs05;
    public static int HName06;
    public static float AApct06;
    public static float hlbs06;
    public static int HName07;
    public static float AApct07;
    public static float hlbs07;
    public static int HName08;
    public static float AApct08;
    public static float hlbs08;
    public static int HName09;
    public static float AApct09;
    public static float hlbs09;
    public static int HName10;
    public static float AApct10;
    public static float hlbs10;
    public static float ratio;
    public static float ttemp;
    public static int YeastName;
    public static float PTemp;
    public static int DHHop1;
    public static int DHDay1;
    public static float DHLbs1;
    public static int DHHop2;
    public static int DHDay2;
    public static float DHLbs2;
    public static int DHHop3;
    public static int DHDay3;
    public static float DHLbs3;
    public static int DHHop4;
    public static int DHDay4;
    public static float DHLbs4;
    public static float RIBU;

    public static void GetRecipesData(String RecipeID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Recipes WHERE RID = '" + RecipeID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                RecpID = rs.getInt("RID");
                RName = rs.getString("RName");
                RRev = rs.getInt("RRev");
                RGT = rs.getFloat("RGT");
                RVol = rs.getFloat("RVol");
                MName01 = rs.getInt("MName01");
                Mpct01 = rs.getFloat("Mpct01");
                MName02 = rs.getInt("MName02");
                Mpct02 = rs.getFloat("Mpct02");
                MName03 = rs.getInt("MName03");
                Mpct03 = rs.getFloat("Mpct03");
                MName04 = rs.getInt("MName04");
                Mpct04 = rs.getFloat("Mpct04");
                MName05 = rs.getInt("MName05");
                Mpct05 = rs.getFloat("Mpct05");
                MName06 = rs.getInt("MName06");
                Mpct06 = rs.getFloat("Mpct06");
                MName07 = rs.getInt("MName07");
                Mpct07 = rs.getFloat("Mpct07");
                MName08 = rs.getInt("MName08");
                Mpct08 = rs.getFloat("Mpct08");
                MName09 = rs.getInt("MName09");
                Mpct09 = rs.getFloat("Mpct09");
                MName10 = rs.getInt("MName10");
                Mpct10 = rs.getFloat("Mpct10");
                gGypsum = rs.getFloat("gGypsum");
                gCaCl = rs.getFloat("gCaCl");
                gEpsomSalt = rs.getFloat("gEpsomSalt");
                gChalk = rs.getFloat("gChalk");
                gTableSalt = rs.getFloat("gTableSalt");
                HName01 = rs.getInt("HName01");
                AApct01 = rs.getFloat("AApct01");
                hlbs01 = rs.getFloat("hlbs01");
                fwh1 = rs.getBoolean("fwh1");
                HName02 = rs.getInt("HName02");
                AApct02 = rs.getFloat("AApct02");
                hlbs02 = rs.getFloat("hlbs02");
                fwh2 = rs.getBoolean("fwh2");
                HName03 = rs.getInt("HName03");
                AApct03 = rs.getFloat("AApct03");
                hlbs03 = rs.getFloat("hlbs03");
                HName04 = rs.getInt("HName04");
                AApct04 = rs.getFloat("AApct04");
                hlbs04 = rs.getFloat("hlbs04");
                HName05 = rs.getInt("HName05");
                AApct05 = rs.getFloat("AApct05");
                hlbs05 = rs.getFloat("hlbs05");
                HName06 = rs.getInt("HName06");
                AApct06 = rs.getFloat("AApct06");
                hlbs06 = rs.getFloat("hlbs06");
                HName07 = rs.getInt("HName07");
                AApct07 = rs.getFloat("AApct07");
                hlbs07 = rs.getFloat("hlbs07");
                HName08 = rs.getInt("HName08");
                AApct08 = rs.getFloat("AApct08");
                hlbs08 = rs.getFloat("hlbs08");
                HName09 = rs.getInt("HName09");
                AApct09 = rs.getFloat("AApct09");
                hlbs09 = rs.getFloat("hlbs09");
                HName10 = rs.getInt("HName10");
                AApct10 = rs.getFloat("AApct10");
                hlbs10 = rs.getFloat("hlbs10");
                ratio = rs.getFloat("ratio");
                ttemp = rs.getFloat("ttemp");
                YeastName = rs.getInt("YeastName");
                PTemp = rs.getFloat("PTemp");
                DHHop1 = rs.getInt("DHHop1");
                DHDay1 = rs.getInt("DHDay1");
                DHLbs1 = rs.getFloat("DHLbs1");
                DHHop2 = rs.getInt("DHHop2");
                DHDay2 = rs.getInt("DHDay2");
                DHLbs2 = rs.getFloat("DHLbs2");
                DHHop3 = rs.getInt("DHHop3");
                DHDay3 = rs.getInt("DHDay3");
                DHLbs3 = rs.getFloat("DHLbs3");
                DHHop4 = rs.getInt("DHHop4");
                DHDay4 = rs.getInt("DHDay4");
                DHLbs4 = rs.getFloat("DHLbs4");
                RIBU = rs.getFloat("RIBU");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Get Sales Data from Database.
    public static int SId;
    public static int CustID;
    public static int BeerID;
    public static int NumHalf;
    public static int NumQtr;
    public static int NumSix;
    public static String SNotes;
    public static int SDisc;
    public static int NumTT;
    public static int NumTW;
    public static int NumSF;
    public static java.sql.Date SDate;

    public static void GetSalesData(String SID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Sales WHERE SId = '" + SID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                SId = rs.getInt("SId");
                CustID = rs.getInt("CustID");
                BeerID = rs.getInt("BeerID");
                NumHalf = rs.getInt("NumHalf");
                NumQtr = rs.getInt("NumQtr");
                NumSix = rs.getInt("NumSix");
                SNotes = rs.getString("SNotes");
                SDate = rs.getDate("SDate");
                //SDate = rs.getString("SDate");
                SDisc = rs.getInt("SDisc");
                NumTT = rs.getInt("NumTT");
                NumTW = rs.getInt("NumTW");
                NumSF = rs.getInt("NumSF");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Get Sales Order data from database.
    public static int SOId;
    public static java.sql.Date SODate;
    public static boolean SOPaid;
    public static int SOCust;
    public static String CheckNo;
    public static String CheckNotes;
    public static String SOCSV;

    public static void GetSalesOrderData(String SOID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM SalesOrder WHERE SOId = '" + SOID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                SOId = rs.getInt("SOId");
                SODate = rs.getDate("SODate");
                SOPaid = rs.getBoolean("SOPaid");
                SOCust = rs.getInt("SOCust");
                CheckNo = rs.getString("CheckNo");
                CheckNotes = rs.getString("CheckNotes");
                SOCSV = rs.getString("SOCSV");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Get State Data from Database.
    public static int StateID;
    public static String StateDesc;
    public static String MoveDesc;

    public static void GetStateData(String SID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM State WHERE StateID = '" + SID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                StateID = rs.getInt("StateID");
                StateDesc = rs.getString("StateDesc");
                MoveDesc = rs.getString("MoveDesc");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Get StockCode Data from Database
    public static int StockID;
    public static int TableID;
    public static int WHID;
    public static int StockVendID;
    public static int StockAltVendID;

    public static void GetStockCodeData(String stid){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM StockCode WHERE StockID = '" + stid + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                StockID = rs.getInt("StockID");
                TableID = rs.getInt("TableID");
                WHID = rs.getInt("WHID");
                StockVendID = rs.getInt("StockVendID");
                StockAltVendID = rs.getInt("StockAltVendID");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Get Supplies Data from Database.
    public static int SupID;
    public static String SupName;
    public static float SupSpoken;
    public static float SupOnHand;
    public static int SupWH;
    public static float SupPrice;
    public static float SupQtyPer;
    public static String SupUnits;
    public static String SupNumber;
    public static float SupOnOrder;

    public static void GetSuppliesData(String SupplyID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Supplies WHERE SupID = '" + SupplyID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                SupID = rs.getInt("SupID");
                SupName = rs.getString("SupName");
                SupSpoken = rs.getFloat("SupSpoken");
                SupOnHand = rs.getFloat("SupOnHand");
                SupWH = rs.getInt("SupWH");
                SupPrice = rs.getFloat("SupPrice");
                SupQtyPer = rs.getFloat("SupQtyPer");
                SupUnits = rs.getString("SupUnits");
                SupNumber = rs.getString("SupNumber");
                SupOnOrder = rs.getFloat("SupOnOrder");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Get Taproom Sales from Database
    public static int TRSId;
    public static java.sql.Date TRSDate;
    public static String TRSName;
    public static String TRSAddr;
    public static String TRSPhone;
    public static boolean TRSRtn;
    public static String TRSCSV;

    public static void GetTRoomSaleData(String TRSID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM TRoomSale WHERE TRSId = '" + TRSID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                TRSId = rs.getInt("TRSId");
                TRSDate = rs.getDate("TRSDate");
                TRSName = rs.getString("TRSName");
                TRSAddr = rs.getString("TRSAddr");
                TRSPhone = rs.getString("TRSPhone");
                TRSRtn = rs.getBoolean("TRSRtn");
                TRSCSV = rs.getString("TRSCSV");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Get Vendor Data from Database
    public static int VID;
    public static String VName;
    public static String VAddr;
    public static String VCity;
    public static String VState;
    public static String VZip;
    public static String VPhone;
    public static String VEmail;
    public static String VNotes;

    public static void GetVendorData(String VenID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Vendors WHERE VID = '" + VenID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                VID = rs.getInt("VID");
                VName = rs.getString("VName");
                VAddr = rs.getString("VAddr");
                VCity = rs.getString("VCity");
                VState = rs.getString("VState");
                VZip = rs.getString("VZip");
                VPhone = rs.getString("VPhone");
                VEmail = rs.getString("VEmail");
                VNotes = rs.getString("VNotes");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Get Wearhouse Data from Database
    public static int WearhouseID;
    public static String WHDesc;
    public static String WHLoc;

    public static void GetWearhouseData(String whid){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Wearhouse WHERE WearhouseID = '" + whid + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                WearhouseID = rs.getInt("WearhouseID");
                WHDesc = rs.getString("WHDesc");
                WHLoc = rs.getString("WHLoc");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Get Yeast Data
    public static int YID;
    public static String YeastDesc;
    public static String YeastVendDisc;
    public static boolean YeastActive;

    public static void GetYeastData(String FID){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM Yeast WHERE YID = '" + FID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                YID = rs.getInt("YID");
                YeastDesc = rs.getString("YeastName");
                YeastVendDisc = rs.getString("YeastDesc");
                YeastActive = rs.getBoolean("YeastActive");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

//--------------------------------------------------------------------------
// Code for random queries, all data gathering queries should be above.
//--------------------------------------------------------------------------

    public static ArrayList<String[]> RunSQLQuery(String qry){

        ArrayList<String[]> list = new ArrayList<String[]>();
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery(qry);
            ResultSet rs = stmt.getResultSet();
            ResultSetMetaData metaData = rs.getMetaData();
            int columns = metaData.getColumnCount();


            while (rs.next()){
                String[] record = new String[columns];
                for (int i=1; i<=columns; i++){
                    record[i-1] = rs.getString(i);
                }
                list.add(record);
            }


        } catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }

    public static ArrayList<String[]> LoadInventory(String qry){
        ArrayList<String[]> list = new ArrayList<String[]>();
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery(qry);
            ResultSet rs = stmt.getResultSet();
            ResultSetMetaData metaData = rs.getMetaData();
            int columns = metaData.getColumnCount();

            while (rs.next()){
                String[] record = new String[columns+1];
                record[0] = "0";
                for (int i=1; i<=columns; i++){
                    record[i] = rs.getString(i);
                }
                list.add(record);
            }
        } catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }

    public static void RunSQLUpdateQuery(String qry){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeUpdate(qry);
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void RunSQLInsertQuery(String tbl, String flds, String vals ){
        try {
            String qry = "INSERT INTO " + tbl + "(" + flds + ")" + "VALUES (" +
                    vals + ")";
            Statement stmt = conn.createStatement();
            int numRows = stmt.executeUpdate(qry,Statement.RETURN_GENERATED_KEYS);
            //stmt.executeUpdate(qry);

            ResultSet rs = stmt.getGeneratedKeys();
            if(rs.next()){
                Global.lastInsertID = rs.getInt(1);
            }

        } catch (Exception e){
            e.printStackTrace();
        }
    }



    public static String GetLastIndex(String tbl, String IDEE){
        String indx = "0";
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM " + tbl);
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                indx = rs.getString(IDEE);
            }
        } catch (Exception e){
            e.printStackTrace();
        }
        return indx;
    }

    public static void PerformInventoryQuery(){
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT * FROM BeerInventory");
            ResultSet rs = stmt.getResultSet();
            InventoryFrame newFrame = new InventoryFrame();
            newFrame.pack();
            newFrame.setLocation(250, 250);
            newFrame.setVisible(true);

            //Parse Data and print to table.
            while (rs.next()){
                GetBeerData(rs.getString("BIBId"));

                int half = rs.getInt("BIHalf");
                int qtr = rs.getInt("BIQtr");
                int six = rs.getInt("BISix");
                int tt = rs.getInt("BITT");
                int tw = rs.getInt("BITW");
                int sf = rs.getInt("BISF");

                int sum = half + qtr + six + tt + tw + sf;

                if (sum != 0){
                    newFrame.AddInvRow(BName, rs.getString("BIHalf"), rs.getString("BIQtr"),
                        rs.getString("BISix"), rs.getString("BITT"), rs.getString("BITW"),
                        rs.getString("BISF"));
                }
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    //Sales Order variables.
    public static float SOCCost;

    public static String GetSalesOrderString(String SOCSV){
        String SOString = "";

        String[] sarry = SOCSV.split(",");
        int number = sarry.length;

        //Set Global variables to zero.
        Global.numHalfBBL = 0;
        Global.numQtrBBL = 0;
        Global.numSixBBL = 0;
        Global.num12Oz = 0;
        Global.num22Oz = 0;
        Global.num750ml = 0;

        SOCCost = 0;

        openDBCon();
        for(int i=0; i<sarry.length; i++){
            float SOTotCost = 0;
            float SOTotBBL = 0;
            float SOXCost = 0;
            GetSalesData(sarry[i]);
            GetBeerData(Integer.toString(BeerID));
            GetCostData(Integer.toString(BCost));
            GetDiscountCodeData(Integer.toString(SDisc));
            SOString += BName + " - ";

            //Check Number of Kegs and record in global prices.
            if(NumHalf > 0){
                Global.numHalfBBL += NumHalf;
                SOString += Integer.toString(NumHalf) + "x 1/2 BBL Kegs, ";
                SOTotCost += HCost * NumHalf;
                SOTotBBL += (NumHalf * 0.5);
            }
            if(NumQtr > 0){
                Global.numQtrBBL += NumQtr;
                SOString += Integer.toString(NumQtr) + "x 1/4 BBL Kegs, ";
                SOTotCost += QCost * NumQtr;
                SOTotBBL += (NumQtr * 0.25);
            }
            if(NumSix > 0){
                Global.numSixBBL += NumSix;
                SOString += Integer.toString(NumSix) + "x 1/6 BBL Kegs, ";
                SOTotCost += SCost * NumSix;
                SOTotBBL += (NumSix * 0.16667);
            }
            if(NumTT > 0){
                Global.num22Oz += NumTT;
                SOString += Integer.toString(NumTT) + "x 22 Oz. Case(s), ";
                SOTotCost += TTCost * NumTT;
                SOTotBBL += (NumTT * Global.TwentyTwoCase * Global.TTtoBBL);
            }
            if(NumTW > 0){
                Global.num12Oz += NumTW;
                SOString += Integer.toString(NumTW) + "x 12 Oz. Case(s), ";
                SOTotCost += TWCost * NumTW;
                SOTotBBL += (NumTW * Global.TwelveCase * Global.TWtoBBL);
            }
            if(NumSF > 0){
                Global.num750ml += NumSF;
                SOString += Integer.toString(NumSF) + "x 750 mL Case(s), ";
                SOTotCost += SFCost * NumSF;
                SOTotBBL += (NumSF * Global.SevenFiftyCase * Global.SFtoBBL);
            }

            SOTotCost = SOTotCost - (SOTotCost * DiscNum);

            SOCCost = SOCCost + SOTotCost;

            SOXCost = ((float)Global.TTBTax * SOTotBBL) + ((float)Global.COTax * SOTotBBL * 31);

            SOTotBBL = 0;
            
            SOCCost += SOXCost;

            float subcost = SOTotCost + SOXCost;

            NumberFormat formatter = new DecimalFormat("#.00");
            String sc = formatter.format(subcost);

            //SOString += " - Cost: $" + subcost + "\n";
            SOString += " - Cost: $" + sc + "\n";
        }
        closeDBCon();

        return SOString;
    }

    public static void ModifyInventoryFromSalesLine(String SID){
        //Look up data sent for sales line, then update the
        //Inventory value accordingly.
        GetSalesData(SID);

        //Get the beer inventory line.
        int tempInt = 0;
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT BIId FROM BeerInventory WHERE BIBId = '" + BeerID + "'");
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                tempInt = rs.getInt("BIId");
            }
        } catch (Exception e){
            e.printStackTrace();
        }

        //Get Beer Inventory
        GetBeerInventoryData(Integer.toString(tempInt));

        String query = "UPDATE BeerInventory SET BIHalf='" +
                Integer.toString(BIHalf - NumHalf) + "',BIQtr='" +
                Integer.toString(BIQtr - NumQtr) + "',BISix='" +
                Integer.toString(BISix - NumSix) + "',BITT='" +
                Integer.toString(BITT - (NumTT*Global.TwentyTwoCase)) + "',BITW='" +
                Integer.toString(BITW - (NumTW*Global.TwelveCase)) + "',BISF='" +
                Integer.toString(BISF - (NumSF*Global.SevenFiftyCase)) +
                "' WHERE BIId='" + Integer.toString(BIId) + "'";

        try {
            Statement stmt = conn.createStatement();
            int updateCount = stmt.executeUpdate(query);
        } catch(SQLException e){
            e.printStackTrace();
        }

    }

    public static double GetUtil(boolean Whole, long minutes){
        if(Whole){
            if(minutes >= 75) return 0.27;
            else if(minutes >= 60) return 0.24;
            else if(minutes >= 45) return 0.22;
            else if(minutes >= 30) return 0.19;
            else if(minutes >= 20) return 0.15;
            else if(minutes >= 10) return 0.12;
            else return 0.05;
        } else {
            if(minutes >= 75) return 0.34;
            else if(minutes >= 60) return 0.30;
            else if(minutes >= 45) return 0.27;
            else if(minutes >= 30) return 0.24;
            else if(minutes >= 20) return 0.19;
            else if(minutes >= 10) return 0.15;
            else return 0.06;
        }
    }

    public static void UpdateMaltInventory(float diff, String MaltID){

        //Get Current Values in Malt DB.
        GetMaltData(MaltID);

        float MOH = MaltOnHand - diff;
        float MS = MaltSpoken - diff;

        String query = "UPDATE Malt SET MaltOnHand='" +
                Float.toString(MOH) + "',MaltSpoken='" +
                Float.toString(MS) +
                "' WHERE MaltID='" + MaltID + "'";

        try {
            Statement stmt = conn.createStatement();
            int updateCount = stmt.executeUpdate(query);
        } catch(SQLException e){
            e.printStackTrace();
        }
    }

    public static void AddMaltInventory(float spokenAdd, float onHandAdd, float onOrderAdd, String MaltID){
        //Get Current Values in Malt DB.
        GetMaltData(MaltID);

        float MOH = MaltOnHand + onHandAdd;
        float MS = MaltSpoken + spokenAdd;
        float MOA = MaltOnOrder + onOrderAdd;

        String query = "UPDATE Malt SET MaltOnHand='" +
                Float.toString(MOH) + "',MaltSpoken='" +
                Float.toString(MS) + "',MaltOnOrder='" +
                Float.toString(MOA) +
                "' WHERE MaltID='" + MaltID + "'";
        try {
            Statement stmt = conn.createStatement();
            int updateCount = stmt.executeUpdate(query);
        } catch(SQLException e){
            e.printStackTrace();
        }
    }

    public static void AddHopInventory(float spokenAdd, float onHandAdd, float onOrderAdd, String HopID){
        //Get Current Values in Malt DB.
        GetHopsData(HopID);

        float HOH = HopOnHand + onHandAdd;
        float HS = HopSpoken + spokenAdd;
        float HOA = HopOnOrder + onOrderAdd;

        String query = "UPDATE Hops SET HopOnHand='" +
                Float.toString(HOH) + "',HopSpoken='" +
                Float.toString(HS) + "',HopOnOrder='" +
                Float.toString(HOA) +
                "' WHERE HID='" + HopID + "'";

        try {
            Statement stmt = conn.createStatement();
            int updateCount = stmt.executeUpdate(query);
        } catch(SQLException e){
            e.printStackTrace();
        }
    }

    public static void UpdateHopsInventory(float diff, String HopID){
        //Get Current Values in Malt DB.
        GetHopsData(HopID);

        float HOH = HopOnHand - diff;
        float HS = HopSpoken - diff;

        String query = "UPDATE Hops SET HopOnHand='" +
                Float.toString(HOH) + "',HopSpoken='" +
                Float.toString(HS) +
                "' WHERE HID='" + HopID + "'";

        try {
            Statement stmt = conn.createStatement();
            int updateCount = stmt.executeUpdate(query);
        } catch(SQLException e){
            e.printStackTrace();
        }
    }

    public static boolean DoesValueExist(String tbl, String column, String value){
        String query = "Select * FROM " + tbl + " WHERE " + column + " ='" + value + "'";
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery(query);
            ResultSet rs = stmt.getResultSet();
            rs.last();
            if(rs.getRow() > 0){
                return true;
            }
        } catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }

    public static String ReturnKey(String tbl, String column, String value, String retVal){
        String query = "Select * FROM " + tbl + " WHERE " + column + " ='" + value + "'";
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery(query);
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                return rs.getString(retVal);
            }
        } catch (Exception e){
            e.printStackTrace();
        }
        return "0";
    }

    public static String ReturnStockCode(String WearID, String TabID){
        String query = "SELECT StockID FROM StockCode WHERE WHID = '" + WearID +
                "' AND TableID = '" + TabID + "'";
        try {
            Statement stmt = conn.createStatement();
            stmt.executeQuery(query);
            ResultSet rs = stmt.getResultSet();
            while (rs.next()){
                return rs.getString("StockID");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
        return "0";
    }


}
